package com.study.controller;


import com.study.enums.ResultCodeEnum;
import com.study.pojo.common.Result;
import com.study.pojo.dto.User;
import com.study.service.LinkService;
import com.study.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/query")
public class LinkController {
    @Autowired
    private LinkService linkService;
    @Autowired
    private UserService userService;

    // 检查是否已有对象
    @RequestMapping("/check")
    public String checkCode(String code) {
        linkService.checkCode(code);
        return "好好爱Ta";
    }

    /**
     * 进行链接
     */
    @RequestMapping("/link")
    public Result<?> link(Integer id, String code) {
        User user = userService.queryUserByUsername(code);
        linkService.link(id, user.getId());
        linkService.link(user.getId(), id);

        return Result.success(ResultCodeEnum.LINK_SUCCESS, user);
    }
}
